import { BaseWindow } from "../../../../component/window/BaseWindow";
import { IStallOtherBoothMessageWindow } from "../interfaces/IStallOtherBoothMessageWindow";
import { Language } from "../../../../../extend/language/Language";
import { ObjCreate } from "../../common/ObjCreate";
import { GScrollPane } from "../../../../../com/mui/controls/GScrollPane";
import { ScrollPolicy } from "../../../../../fl/controls/ScrollPolicy";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { KeyCode } from "../../../../../com/gengine/keyBoard/KeyCode";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { MsgManager } from "../../../manager/MsgManager";
import { SPublicMiniPlayer } from "../../../../../Message/Public/SPublicMiniPlayer";
import { PlayerOpRegister } from "../../common/menu/PlayerOpRegister";
import { PlayerMiniInfo } from "../../../model/PlayerMiniInfo";
import { Global } from "../../../../../com/gengine/global/Global";
import { DateParser } from "../../../../common/tools/DateParser";
import { FilterConst } from "../../../../component/gconst/FilterConst";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { SPlayerItem } from "../../../../../Message/Public/SPlayerItem";
import { ItemData } from "../../../resource/info/ItemData";
import { ItemDataWorking } from "../../chat/chatViewData/ItemDataWorking";
import { ColorConfig } from "../../../resource/ColorConfig";
import { GTextInput } from "../../../../../com/mui/controls/GTextInput";
import { GButton } from "../../../../../com/mui/controls/GButton";
type int = number;
//class OtherBoothMessageWindow
    
    export  class OtherBoothMessageWindow extends BaseWindow implements IStallOtherBoothMessageWindow
    {
        constructor()
        {
            super();
            setSize(235, 371);
            titleHeight = 27;
            title = Language.getString(40807);
            this.initView();
            this.addListeners();
            return;
        }

        /* internal  */initView(): void
        {
            this._inputBoothADMsg = ObjCreate.createGTextInput(17, 38, 200, 76, this);
            this._inputBoothADMsg.editable = false;
            this._inputMsgBoard = ObjCreate.createGTextInput(18, 335, 148, 20, this);
            this._btnSend = ObjCreate.createGButton(Language.getString(40810), 168, 334, 47, 22, this);
            var loc1=ObjCreate.createBg(17, 144, 200, 162, this);
            this._spMsgContainer = new Object /* flash.display.Sprite */();
            this.addChild(this._spMsgContainer);
            this._scrollPane = new GScrollPane();
            this._scrollPane.x = 17;
            this._scrollPane.y = 144;
            this._scrollPane.width = 200;
            this._scrollPane.height = 162;
            this._scrollPane.styleName = "GScrollPane";
            this._scrollPane.verticalScrollPolicy = ScrollPolicy.AUTO;
            this._scrollPane.horizontalScrollPolicy = ScrollPolicy.OFF;
            this._scrollPane.source = this._spMsgContainer;
            this.addChild(this._scrollPane);
            this._scrollPane.update();
            this._inputBoothADMsg.maxChars = 50;
            this._inputMsgBoard.maxChars = 30;
            this._inputBoothADMsg.validateNow();
            this._inputMsgBoard.validateNow();
            this._inputBoothADMsg.setStyle("textFormat", GlobalStyle.textFormat1);
            this._inputMsgBoard.setStyle("textFormat", new GTextFormat(FontUtil.songtiName, 12, 16777215));
            this._inputBoothADMsg.text = Language.getString(40811);
            this._inputMsgBoard.text = this.defaultInputText;
            return;
        }

        /* internal  */addListeners(): void
        {
            this._btnSend.addEventListener(flash.events.MouseEvent.CLICK, this.SendHandler);
            this._inputMsgBoard.addEventListener(flash.events.FocusEvent.FOCUS_IN, this.FocusHandler);
            this._inputMsgBoard.addEventListener(flash.events.FocusEvent.FOCUS_OUT, this.FocusHandler);
            this._inputMsgBoard.addEventListener(flash.events.KeyboardEvent.KEY_DOWN, this.enterSendHandler);
            return;
        }

        /* internal  */SendHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.send();
            return;
        }

        /* internal  */enterSendHandler(arg1: Object /* flash.events.KeyboardEvent */): void
        {
            if (arg1.keyCode == KeyCode.ENTER) 
            {
                this.send();
            }
            return;
        }

        /* internal  */send(): void
        {
            if (!(this._inputMsgBoard.text == "") && !(this._inputMsgBoard.text == this.defaultInputText)) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.StallAddMsg, this._inputMsgBoard.text));
                this._inputMsgBoard.text = "";
            }
            else 
            {
                MsgManager.showRollTipsMsg(Language.getString(40813));
            }
            return;
        }

        /* internal  */FocusHandler(arg1: Object /* flash.events.FocusEvent */): void
        {
            if (arg1.type == flash.events.FocusEvent.FOCUS_IN && this._inputMsgBoard.text == this.defaultInputText) 
            {
                this._inputMsgBoard.text = "";
            }
            else if (arg1.type == flash.events.FocusEvent.FOCUS_OUT && this._inputMsgBoard.text == "") 
            {
                this._inputMsgBoard.text = this.defaultInputText;
            }
            return;
        }

        public addLeaveWordMsg(arg1: Date, arg2: SPublicMiniPlayer, arg3: string): void
        {
            var date: Date;
            var player: SPublicMiniPlayer;
            var content: string;
            var strName: string;
            var time: string;
            var tfMsg: Object /* flash.text.TextField */;
            var onLinkTextClickHandler: Function;

            var loc1;
            strName = null;
            time = null;
            tfMsg = null;
            onLinkTextClickHandler = null;
            date = arg1;
            player = arg2;
            content = arg3;
            onLinkTextClickHandler = (arg1: Object /* flash.events.TextEvent */): void
            {
                PlayerOpRegister.ShowOpList(new PlayerMiniInfo(player), Global.stage.mouseX, Global.stage.mouseY);
                return;
            }
            strName = player.name;
            time = DateParser.parse(date, "hh: mm");
            tfMsg = new Object /* flash.text.TextField */();
            tfMsg.x = 0;
            tfMsg.y = this.totleHeight;
            tfMsg.width = 185;
            tfMsg.autoSize = flash.text.TextFieldAutoSize.LEFT;
            tfMsg.multiline = true;
            tfMsg.wordWrap = true;
            tfMsg.filters = [FilterConst.glowFilter];
            tfMsg.htmlText = "<textFormat leading=\'4\'>" + HTMLUtil.addColor(time, "#82fbff") + "<a href=\'event: 1\'>" + HTMLUtil.addColor("【" + strName + "】", GlobalStyle.color5) + "</a>" + HTMLUtil.addColor("：" + content, "#82fbff") + "</textFormat>";
            tfMsg.addEventListener(flash.events.TextEvent.LINK, onLinkTextClickHandler);
            tfMsg.mouseWheelEnabled = false;
            this._spMsgContainer.addChild(tfMsg);
            this.totleHeight = this.totleHeight + tfMsg.height;
            this._spMsgContainer.height = this.totleHeight;
            this._scrollPane.update();
            this._scrollPane.verticalScrollPosition = this._scrollPane.maxVerticalScrollPosition;
            return;
        }

        public addBuyMsg(arg1: Date, arg2: SPublicMiniPlayer, arg3: int, arg4: int, arg5: int, arg6: SPlayerItem): void
        {
            var date: Date;
            var player: SPublicMiniPlayer;
            var gold: int;
            var coin: int;
            var amount: int;
            var playerItem: SPlayerItem;
            var itemData: ItemData;
            var time: string;
            var tfMsg: Object /* flash.text.TextField */;
            var strPriceDescription: string;
            var onLinkTextClickHandler: Function;

            var loc1;
            tfMsg = null;
            onLinkTextClickHandler = null;
            date = arg1;
            player = arg2;
            gold = arg3;
            coin = arg4;
            amount = arg5;
            playerItem = arg6;
            onLinkTextClickHandler = (arg1: Object /* flash.events.TextEvent */): void
            {
                PlayerOpRegister.ShowOpList(new PlayerMiniInfo(player), Global.stage.mouseX, Global.stage.mouseY);
                return;
            }
            itemData = new ItemData(playerItem);
            time = DateParser.parse(date, "hh: mm");
            tfMsg = new Object /* flash.text.TextField */();
            tfMsg.x = 0;
            tfMsg.y = this.totleHeight;
            tfMsg.width = 185;
            tfMsg.autoSize = flash.text.TextFieldAutoSize.LEFT;
            tfMsg.multiline = true;
            tfMsg.wordWrap = true;
            tfMsg.filters = [FilterConst.glowFilter];
            tfMsg.mouseWheelEnabled = false;
            strPriceDescription = "";
            if (gold > 0) 
            {
                strPriceDescription = gold.toString() + Language.getString(40814);
            }
            else 
            {
                strPriceDescription = coin.toString() + Language.getString(40815);
            }
            tfMsg.htmlText = "<textFormat leading=\'4\'>" + HTMLUtil.addColor(time, "#ffc703") + "<a href=\'event: 1\'>" + HTMLUtil.addColor("【" + player.name + "】", GlobalStyle.color5) + "</a>" + HTMLUtil.addColor(Language.getStringByParam(40816, strPriceDescription, amount.toString()) + HTMLUtil.addColor(ItemDataWorking.getItemDataName(itemData), ColorConfig.instance.getItemColor(itemData.itemInfo.item.color).color), "#ffc703") + "</textFormat>";
            tfMsg.addEventListener(flash.events.TextEvent.LINK, onLinkTextClickHandler);
            tfMsg.mouseWheelEnabled = false;
            this._spMsgContainer.addChild(tfMsg);
            this.totleHeight = this.totleHeight + tfMsg.height;
            this._spMsgContainer.height = this.totleHeight;
            this._scrollPane.update();
            this._scrollPane.verticalScrollPosition = this._scrollPane.maxVerticalScrollPosition;
            return;
        }

        public clearMsg(): void
        {
            var loc1=(this._spMsgContainer.numChildren - 1);
            while (loc1 >= 0) 
            {
                this._spMsgContainer.removeChildAt(loc1);
                --loc1;
            }
            this.totleHeight = 0;
            return;
        }

        public updateBoothADMsg(arg1: string): void
        {
            this._inputBoothADMsg.text = arg1;
            return;
        }

        /* internal */ /* const */defaultInputText: string=Language.getString(40806);

        /* internal */ /* var */_inputBoothADMsg: GTextInput;

        /* internal */ /* var */_inputMsgBoard: GTextInput;

        /* internal */ /* var */_scrollPane: GScrollPane;

        /* internal */ /* var */_spMsgContainer: Object /* flash.display.Sprite */;

        /* internal */ /* var */_btnSend: GButton;

        /* internal */ /* var */totleHeight: number=0;
    }
